x86/pv-shim: correct ballooning down for compat guests
authorIgor Druzhinin <igor.druzhinin@citrix.com>
Fri, 28 Oct 2022 13:49:33 +0000 (15:49 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 28 Oct 2022 13:49:33 +0000 (15:49 +0200)
commit1d7fbc535d1d37bdc2cc53ede360b0f6651f7de1
tree1fbbcb198d0d57a379fb120aad43dbd0dbabb79d
parenta0bfdd201ea12aa5679bb8944d63a4e0d3c23160
x86/pv-shim: correct ballooning down for compat guests

From: Igor Druzhinin <igor.druzhinin@citrix.com>

The compat layer for multi-extent memory ops may need to split incoming
requests. Since the guest handles in the interface structures may not be
altered, it does so by leveraging do_memory_op()'s continuation
handling: It hands on non-initial requests with a non-zero start extent,
with the (native) handle suitably adjusted down. As a result
do_memory_op() sees only the first of potentially several requests with
start extent being zero. In order to be usable as overall result, the
function accumulates args.nr_done, i.e. it initialized the field with
the start extent. Therefore non-initial requests resulting from the
split would pass too large a number into pv_shim_offline_memory().

Address that breakage by always calling pv_shim_offline_memory()
regardless of current hypercall preemption status, with a suitably
adjusted first argument. Note that this is correct also for the native
guest case: We now simply "commit" what was completed right away, rather
than at the end of a series of preemption/re-start cycles. In fact this
improves overall preemption behavior: There's no longer a potentially
big chunk of work done non-preemptively at the end of the last
"iteration".

Fixes: b2245acc60c3 ("xen/pvshim: memory hotplug")
Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
xen/common/memory.c